#pragma once

#define INITGUID

#include <list>
#include "Functor.h"
#include "EnginePointer.h"
#include "IEngineSystem.h"
#include "WindowSettings.h"
#include "SystemCollection.h"

// {E1FBCF1F-C10E-41fb-A342-D142849A5A1A}
DEFINE_GUID(WINDOW_SYSTEM_GUID, 
0xe1fbcf1f, 0xc10e, 0x41fb, 0xa3, 0x42, 0xd1, 0x42, 0x84, 0x9a, 0x5a, 0x1a);

class WindowSystem : public IEngineSystem
{
private:
	enum WindowState
	{
		NEW,
		RUNNING,
		CLOSING,
		CLOSED,
		DESTROYING,
		DESTROYED,
	};
public:
	WindowSystem(EnginePointer<SettingsManager>& settings, EnginePointer<IMessageQueue>& messages);
	~WindowSystem();

	HRESULT Initialize(EnginePointer<SystemCollection>& systems);
	void Update(LONGLONG timeElapsed);
	void Clean();
	BOOL IsClean();
	GUID getSystemIdentifier();

	HWND getHWnd();

	AUTO_SIZE;
private:
	static WindowSystem* currentSystem;

	HWND hWnd;
	WindowState state;

	HRESULT InitializeWindow();
	void SendResizedMessage();
	void Close();
	void Destroy();
	static LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
};
